package hz.mobileproject.pda.ui.activity.work;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.text.SimpleDateFormat;
import java.util.List;

import cn.droidlover.xdroidmvp.mvp.XActivity;
import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.request.YiDianImpBuWei;
import hz.mobileproject.pda.entity.response.YiDianImpBean;
import hz.mobileproject.pda.listener.IKeyPlace;
import hz.mobileproject.pda.presenter.PKeyPlace;
import hz.mobileproject.pda.ui.adapter.YiDianImpBuWeiAdapter;

/**
 * 重点部位  巡查记录界面
 */
public class KeyPlace_logActivity extends XActivity<PKeyPlace> implements IKeyPlace {

    private static final String TAG = "KeyPlace_logActivity";
    private Gson gson;
    private SPUtils mSPUtils;
    private RecyclerView recyclerView_keyplace;
    private List<YiDianImpBean> mYiDianImpBeanList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onWidgetClick(View view) {

    }

    @Override
    public void initData(Bundle savedInstanceState) {
        gson = new Gson();
        recyclerView_keyplace = (RecyclerView) findViewById(R.id.recyclerView_keyplace);
        mSPUtils = SPUtils.getInstance("app_login");
        String cusNumber = mSPUtils.getString("cusNumber_imp");
        String queryDept = mSPUtils.getString("departmentId_imp");
//        String time = "2017-08-22";
        String time = TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd"));
        YiDianImpBuWei yiDianImpBuWei = new YiDianImpBuWei(cusNumber,queryDept,time);
        getP().loadData(yiDianImpBuWei,1);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_key_place_log;
    }

    @Override
    public PKeyPlace newP() {
        return new PKeyPlace();
    }

    @Override
    public void showError(Exception e) {

    }

    //P过来的显示数据
    @Override
    public void showData(String s, int type) {
        switch (type) {
            case 1: {
                LogUtils.e(s);
                mYiDianImpBeanList = gson.fromJson(s,new TypeToken<List<YiDianImpBean>>(){}.getType());
                recyclerView_keyplace.setLayoutManager(new LinearLayoutManager(KeyPlace_logActivity.this));
                YiDianImpBuWeiAdapter yiDianImpBuWeiAdapter = new YiDianImpBuWeiAdapter(mYiDianImpBeanList);
                recyclerView_keyplace.setAdapter(yiDianImpBuWeiAdapter);

            }
            break;
        }
    }
}
